package org.zls.client;

import org.zls.client.login.Callback;
import org.zls.client.service.ServerService;

import com.google.gwt.user.client.Random;

public class Util {
	
	public static void validateLogin(String e, String p) {
		
		Callback.MystifyCallback mcallback = new Callback.MystifyCallback(e.hashCode(), p.hashCode());
		ServerService.Util.getInstance().getPublicKey(mcallback);
		
	}

	public static long mystify(int msg, long key) {
		
		long salt = 0;
		
		while (salt < 1000) {
			salt = Random.nextInt(10000);
		}
		
		key = key * 10000 + salt;

		System.out.println("Original message: " + msg);
		System.out.println("Encoded message: " + (key ^ msg));
		System.out.println("salt: " + salt);
		System.out.println("Sent message: " + ((key ^ msg) * 10000 + salt));
		
		return ((key ^ msg) * 10000 + salt);
	}
}
// %[argument_index$][flags][width][.precision]conversion
//
//
// The optional argument_index is a decimal integer indicating the position of
// the argument in the argument list. The first argument is referenced by "1$",
// the second by "2$", etc.
//
// The optional flags is a set of characters that modify the output format. The
// set of valid flags depends on the conversion.
//
// The optional width is a non-negative decimal integer indicating the minimum
// number of characters to be written to the output.
//
// The optional precision is a non-negative decimal integer usually used to
// restrict the number of characters. The specific behavior depends on the
// conversion.
//
// The required conversion is a character indicating how the argument should be
// formatted. The set of valid conversions for a given argument depends on the
// argument's data type. 